<template>
  <div class="goods-type">
    <el-tabs class="type-tabs">
      <el-tab-pane label="咖啡">
        <ul class="cookList">
          <li v-for="item in coffers" @click="add_to_orderList(item)">
            <div class="left-Img">
              <img :src="'src/assets/cofferimg/'+item.image" width="100%"/>
            </div>
            <div class="right-text">
              <span class="foodName">{{ item.name }}</span>
              <span class="foodPrice">￥{{ item.price }}元</span>
            </div>
          </li>
        </ul>
      </el-tab-pane>

      <el-tab-pane label="茶饮">
        <ul class="cookList">
          <li v-for="item in teas" @click="add_to_orderList(item)">
            <div class="left-Img">
              <img :src="'src/assets/cofferimg/'+item.image" width="100%"/>
            </div>
            <div class="right-text">
              <span class="foodName">{{ item.name }}</span>
              <span class="foodPrice">￥{{ item.price }}元</span>
            </div>
          </li>
        </ul>
      </el-tab-pane>

      <el-tab-pane label="甜点">
        <ul class="cookList">
          <li v-for="item in cakes" @click="add_to_orderList(item)">
            <div class="left-Img">
              <img :src="'src/assets/cofferimg/'+item.image" width="100%"/>
            </div>
            <div class="right-text">
              <span class="foodName">{{ item.name }}</span>
              <span class="foodPrice">￥{{ item.price }}元</span>
            </div>
          </li>
        </ul>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script setup>
import {onMounted, ref} from "vue"
import orderTable from "./OrderTable.vue"
import axios from "axios";
import emitter from "../../untils/bus";

const coffers = ref([])
const cakes = ref([])
const teas = ref([])
let data = [];

// 在组件挂载后执行回调函数
onMounted(() => {
  getData()
})

//获取当前页数据
const getData = () => {
  axios.get('http://192.168.65.182:8080/product/getAll', {})
      .then(res => {
        console.log(res.data)
        // coffers.value = res.data;
        coffers.value = res.data.filter(item => {
          return item.categoryid === 1
        })
        teas.value = res.data.filter(item => {
          return item.categoryid === 2
        })
        cakes.value = res.data.filter(item => {
          return item.categoryid === 3
        })
      })
      .catch(error => {
        console.error(error);
      });
};

const add_to_orderList = (item) => {
  // alert(item.price)
  goods_table_data.add(item)
  totalMoney += item.price
  totalCount ++;
}

</script>

<style scoped>

.goods-type /deep/ .el-tabs__item {
  font-size: 16px;
}

.goods-type {
  /*margin-top: 40px;*/
  padding: 0 10px;
  box-sizing: border-box;
  background-color: #fff7f7;
  height: 100%;
  --el-transfer-panel-body-height: 100%;
}

.goods-type .cookList {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
}

.goods-type .cookList li {
  width: 30%;
  list-style: none;
  border: 1px solid #e5e9f2;
  overflow: hidden;
  background-color: #fff;
  margin: 1%;
  border-radius: 5px;
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.1);
  transition: all 0.3s;
}

.goods-type .cookList li :hover {
  transform: scale(1.05);
}

.goods-type .cookList li .left-Img {
  width: 40%;
  height: 100%;
}

.goods-type .cookList li .left-Img img {
  display: inline-block;
  width: 100%;
  height: 100%;
}

.goods-type .cookList li .right-text {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.goods-type .cookList li .foodName {
  font-size: 1rem;
  padding: 1rem;
  box-sizing: border-box;
  font-weight: 600;
  color: #f56c6c;
}

.goods-type .cookList li .foodPrice {
  font-size: 1rem;
  padding: 10px;
  box-sizing: border-box;
}

.type-tabs{
  padding-top: 40px;
}

</style>